package com.lfy.auth.listener;

import com.lfy.auth.domain.msg.RegMsg;
import com.lfy.common.constant.EmailConstant;
import com.lfy.common.util.SendEmailUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
/**
 * 登录注册事件
 *
 * @author <a href="https://www.lvfeiy.top">吕飞扬</a>
 * @date 2023/10/13 16:29
 */
@Component
@Slf4j
public class AuthListener {
    /**
     * 注册发送邮件
     */
    @EventListener(classes = RegMsg.class)
    @Async
    public void sendEmail(RegMsg regMsg){
        String code = regMsg.getCode();
        String to = regMsg.getTo();
        try {
            SendEmailUtil.sendEmail(to, EmailConstant.EMAIL_TITLE,EmailConstant.emailContent(code));
        } catch (Exception e) {
            log.info("register send email error ",e);
        }
    }
}
